package controllers

import (
	"github.com/astaxie/beego"
)

// 基础控制器
type BaseController struct {
	beego.Controller
	PageSize int

}

func (c *BaseController) Prepare() {
	//if c.Ctx.Request.RequestURI != "/drp/wechat/auth" && c.Ctx.Request.RequestURI != "/drp/wechat/detail" {
	//	user := c.GetSession("user")
	//	if user == nil {
	//		c.Ctx.Redirect(401, "/error/403") //若Session中无用户ID则302重定向至登陆页面
	//
	//	} else {
	//
	//		u := user.(wechat.UserInfo)
	//		s := delivery.Staff{
	//			Openid: u.OpenId,
	//		}
	//		if err := s.Auth(); err != nil {
	//			c.Ctx.Redirect(401, "/error/403") //无权限 重定向
	//		}
	//	}
	//}
	if c.GetSession("user") == nil {
		c.Redirect("/login", 302)
	}

	// 后台全局CSRF防范
	c.Data["CSRF_TOKEN"] = c.XSRFToken()
	c.PageSize, _ = beego.AppConfig.Int("page.size")

	// 后台模板基础布局
	c.Layout = "layout/base.html"
	c.LayoutSections = make(map[string]string)



	//c.LayoutSections["Tabbar"] = "layouts/tabbar.html"
	c.LayoutSections["HtmlHead"] = "layout/header.html"
	c.LayoutSections["Scripts"] = ""
	//c.Data["Nickname"] = c.GetSession("nickname")
	//c.Data["AdminId"] = c.GetSession("adminId")
	//c.LayoutSections["HtmlHeader"] = "admin/layouts/header.html"
	//c.LayoutSections["Menu"] = "admin/layouts/menu.html"
}
